var bunyan = require('bunyan');
var nodemailer = require('nodemailer')
 
var transporter  = nodemailer.createTransport({
    service: 'QQ',
    auth: {
        user: '100703360@qq.com',//发送者邮箱
        pass: 'upgsswajgikdcaha' //邮箱第三方登录授权码
    },
    logger: bunyan.createLogger({
        name: 'nodemailer'
    }),//打印日志
    debug: true
},{
    from: '100703360@qq.com',//发送者邮箱
    headers: {
        'X-Laziness-level': 1000
    }
});
 
/**
 * @param {String} recipient 收件人
 * @param {String} subject 发送的主题
 * @param {String} html 发送的html内容
 */

var sendMail = function (recipient, subject, html,fn) {
    var message = {
        // Comma separated lsit of recipients 收件人用逗号间隔
        to: recipient,
        // Subject of the message 信息主题
        subject:  subject,
        // Html body
        html: html,
    };
    transporter.sendMail(message, (error, info) => {
        if (error) {
            return;
        }
        fn();
        transporter.close();
    });
}
module.exports = sendMail;
